package fr.umlv.rtsjtaskserver.client;

import java.util.ArrayList;
import java.util.List;

import javax.realtime.AsyncEventHandler;
import javax.realtime.OneShotTimer;
import javax.realtime.RelativeTime;

import fr.umlv.rtsjtaskserver.server.BackgroundScheduling;

/**
 * Test the Background Policy
 * 
 * @author Moreau Alan
 */
public class BackgroundPolicyClient{
	
	public static void main(String[] args) {
		final List<AsyncEventHandler> handlers = new ArrayList<AsyncEventHandler>();
		final List<RelativeTime> times = new ArrayList<RelativeTime>();
		
		handlers.add(createPrintHandler("My Asyn Task num "+1));
		times.add(new RelativeTime(2000, 0));	
		
		handlers.add(createPrintHandler("My Asyn Task num "+2));
		times.add(new RelativeTime(4000, 0));
	
		handlers.add(createPrintHandler("My Asyn Task num "+3));
		times.add(new RelativeTime(6000, 0));
		
		final List<OneShotTimer> timers = BackgroundScheduling.buildTimer(handlers, times);
		
		for(OneShotTimer timer: timers){
			timer.start();
		}
		
		try {
			Thread.sleep(8000);
		} catch (Exception e) {
			
		}
	}
	
	private static AsyncEventHandler createPrintHandler(final String diplayedMessage){
		return new AsyncEventHandler(){
			@Override
			public void handleAsyncEvent() {
				System.out.println(diplayedMessage);
			}
		};
	}
}
